package Student;

import com.alibaba.fastjson.JSON;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MapTest extends Mapper<LongWritable, Text, Students, NullWritable> {
    Students k = new Students();
    Students students = new Students();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //将json字符串转换成students对象
        students = JSON.parseObject(value.toString(), Students.class);
        //为k赋值
        k.set(students.getId(),students.getClassName(),students.getAge(),students.getSex(),students.getClassName());
        //写出
        context.write(k, NullWritable.get());
    }
}
